﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NHibernate;
using NHibernate.Cfg;
using NHibernate.Tool;
using FluentNHibernate.Cfg;
using FluentNHibernate;
using FluentNHibernate.Cfg.Db;
using NHibernate.Tool.hbm2ddl;
using SPPD.model;

namespace SPPD
{
    class nhibernate 
    {
        const string connString = "server=10.151.34.218; " +
            "database=SPPD;" +
            "User ID=admin;" +
            "Password=1234;" +
            "Trusted_Connection=False;"; //base  vc_attributes    

        public void createTable()
        {
                 Fluently.Configure()
                .Database(MsSqlConfiguration.MsSql2008.ConnectionString(connString))
                .Mappings(m => m.FluentMappings.AddFromAssemblyOf<transaksi>())
                .ExposeConfiguration(CreateSchema)
                .BuildConfiguration();
        }

        private static void CreateSchema(Configuration cfg)
        {
            var schemaExport = new SchemaExport(cfg);
            schemaExport.Drop(false, true);
            schemaExport.Create(false, true);
        }

        public ISessionFactory CreateSessionFactory()
        {
            return Fluently.Configure()
                .Database(MsSqlConfiguration.MsSql2008.ConnectionString(connString))
                .Mappings(m => m.FluentMappings.AddFromAssemblyOf<transaksi>())
                .BuildSessionFactory();
        }

    }
}
